<?php
/**
 * Created by PhpStorm.
 * User: mac
 * Date: 2017/6/8
 * Time: 下午2:27
 */

namespace Mq\Base;


use Mq\Core\Application;

class FacadeService
{

    public static $resolvedInstance = [];

    public function __construct()
    {
        //
    }

    public static function getFacadeAccessor()
    {
        //
    }

    public static function __callstatic($method, $arg)
    {
        $instance = self::getJobInstance();
        return call_user_func_array(array($instance, $method), $arg);
    }

    //返回实例
    public static function getJobInstance()
    {
        return self::resolveJobInstance(static::getFacadeAccessor());
    }

    //获取相关实例
    public static function resolveJobInstance($name)
    {

        if (is_object($name)) {
            return $name;
        }
        $abstract = Application::getInstance()->getJobInstance($name);
        if (isset($abstract)) {
            return self::$resolvedInstance[$name] = $abstract;
        }

        $provider = Application::getInstance()->getJobProvider($name);
        if (isset($provider)) {
            return self::$resolvedInstance[$name] = $provider::getInstance();
        }

        return self::$resolvedInstance[$name] = $name::getInstance();
    }

}